/**
 * 响应拦截
 * @param {Object} http 
 */
module.exports = (vm) => {
	uni.$u.http.interceptors.response.use((response) => {
		/* 对响应成功做点什么 可使用async await 做异步操作*/
		const data = response.data
		if (data.code !== 1) { // 服务端返回的状态码不等于200，则reject()
			uni.$u.toast(data.msg)
			if (data.code == 10000) {
				uni.navigateTo({
					url: '/pages/user/login/login',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
			// 否则返回一个pending中的promise
			return Promise.reject(data)
		}
		return data || {}
	}, (response) => {
		console.log(response);
		/*  对响应错误做点什么 （statusCode !== 200）*/
		if (response.statusCode == 1000) {
			uni.navigateTo({
				url: '/pages/user/login/login',
				success: res => {
					uni.showToast({
						title: 'please log in first',
						icon: "none"
					});
				},
				fail: () => {},
				complete: () => {}
			});
		}else{
			uni.showToast({
				title: response.data,
				icon: "none"
			});
		}
		return Promise.reject(response)
	})
}